package com.vitabuybuy.tv.ui.mine.talent

import android.os.Bundle
import android.webkit.URLUtil
import androidx.lifecycle.Observer
import com.vitabuybuy.tv.R
import com.vitabuybuy.tv.databinding.ActivityApplyExpertBinding
import com.library.common.base.BaseActivity
import com.vitabuybuy.tv.ui.viewmodel.NoViewModel
import com.vitabuybuy.tv.utils.WebViewUtils
import kotlinx.android.synthetic.main.activity_apply_expert.*

class ApplyExpertActivity : BaseActivity<NoViewModel, ActivityApplyExpertBinding>() {
    override val isUseBaseTitleBar: Boolean
        get() = true
    override val layoutId: Int
        get() = R.layout.activity_apply_expert

    override fun initView(savedInstanceState: Bundle?) {
        setTitle(getString(R.string.apply_expert))
        WebViewUtils.defaultSetting(webView)
    }

    override fun observeData() {
        viewModel.loadWebViewContet(27)
        viewModel.webContent.observe(this, Observer {
            if (URLUtil.isValidUrl(it.content)) {
                webView.loadUrl(it.content)
            } else {
                webView.loadDataWithBaseURL(
                    null,
                    WebViewUtils.htmlContent(it.content),
                    "text/html",
                    "UTF-8",
                    null
                )
            }
        })
    }
    override fun eventHandling() {
        btnApplyOpen.setOnClickListener {
            ExpertInfoActivity.openActivity(mContext)
            finish()
        }
    }
    companion object {
        fun openActivity(mContext: BaseActivity<*, *>) {
            mContext.startActivity(null, ApplyExpertActivity::class.java)
        }
    }
}
